//1.2.1、首页菜单栏api.....................................................开始
//1.AJAX请求数据
$.get(
  "http://chst.vip:1234/api/getindexmenu",
  {},
  (res) => {
    // console.log(res.result);
    let html = "";
    //2.AJAX请求数据后将数据展示在首页
    $(res.result).each(function (i, item) {
      // console.log(item.img);
      html += `<li indexmenuId=${item.indexmenuId}  name=${item.name}  titlehref=${item.titlehref} img=${item.img}
        ${item.img} 
      
      <p>${item.name}</p>
      
      </li>
      `;
    });
    $(".contenttop").html(html);
  },
  "json"
);
//1.2.1、首页菜单栏api.....................................................结束
//1.2.2、首页的折扣列表中的数据api.....................................................开始
$.get(
  "http://chst.vip:1234/api/getmoneyctrl",
  {},
  (res) => {
    let html = "";
    // console.log(res.result);
    $(res.result).each((i, item) => {
      let data = item.productImgSm;
      // console.log(data.split("=")[4]);
      // console.log(data.split("=")[3].split(" ")[0]);
      // console.log(data.split("=")[3].split(" ")[0].split('"')[0]);
      //处理网址数据  data   网址的变量
      html += ` <li>  


     <img src= ${data.split("=")[3].split(" ")[0].split('"')[0]} title='${
        data.split("=")[4]
      }'>
    <div> 
      <p class="productName">${item.productName}</p>
      <p class="productPinkage">${item.productPinkage}</p>
      <span class="productFrom">${item.productFrom}</span>
      <span class="productTime">${item.productTime}</span>
      <span class="productComCount">${item.productComCount}</span>
    </div>
  </li>`;
    });
    $(".contentfoot").html(html);
  },
  "json"
);

//1.2.2、首页的折扣列表中的数据api.....................................................结束

//首页的跳转- 根据indexmenuid 属性判断跳转不同的界面
$(".contenttop").on("click", "li", function () {
  switch (Number($(this).attr("indexmenuid"))) {
    case 0:
      location.href = "./category.html";
      break;

    case 1:
      location.href = "./moneyctrl.html";
      break;

    case 2:
      location.href = "./inlanddiscount.html";
      break;

    case 3:
      location.href = "./baicaijia.html";
      break;
    case 4:
      location.href = "./moneyctrl.html";
      break;

    case 5:
      location.href = "./coupon.html";
      break;
    case 6:
      location.href = "#";
      break;

    case 7:
      location.href = "#";
      break;
    case 8:
      location.href = "./gsproduct.html";
      break;

    case 9:
      location.href = "./category.html";
      break;
    case 10:
      location.href = "./sitenav.html";
      break;

    case 11:
      location.href = "./LastPage.html";
      break;

    default:
      break;
  }
});
